package com.bailun91.auth.controller;


import com.bailun91.auth.dto.UserAgentDto;
import com.bailun91.auth.entity.JsonData;
import com.bailun91.auth.entity.User;
import com.bailun91.auth.jwt.JwtToken;
import com.bailun91.auth.jwt.JwtUtil;
import com.bailun91.auth.service.LoginService;
import com.bailun91.auth.service.UserService;
import com.bailun91.auth.util.ShiroUtils;
import com.bailun91.auth.util.UserAgentUtil;
import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Enumeration;

@RestController
public class LoginController {

    @Autowired
    UserService userService;
    @Autowired
    LoginService loginService;

    @RequestMapping("/login")
    @ResponseBody
    public JsonData login(String username, String password, HttpServletRequest request, HttpServletResponse response) {

        return loginService.login(username, password, request, response);
    }


    @RequestMapping("/logout")
    @ResponseBody
    public JsonData logout(HttpServletRequest request, HttpServletResponse response) {
        return loginService.logout(request, response);
    }

    @RequestMapping("/403")
    public JsonData forbid() {
        return JsonData.buildError("没权限");
    }

    @RequestMapping("/401")
    public JsonData rep401() {
        return JsonData.buildError("请先登录");
    }


}
